package com.suray.basic.wcs.plc.core;


public class PlcWordCache {
    // 缓存更新时间
    public final static int UPDATE_CATCH_TIME = 700;
    // 缓存超时时间
    private final static long TIME_OUT = 3000;
    private long updateTime;//上次更新数据的时间
    private int[] plcStatus;

    public PlcWordCache() {
        super();
    }

    public int[] getPlcStatus() {
        return plcStatus;
    }

    public void setPlcStatus(int[] plcStatus) {
        this.plcStatus = plcStatus;
    }

    /**
     * @param plcStatus plc结果
     * @param start     起始位置
     * @param end       结束位置
     */
    public void setPlcStatus(int[] plcStatus, int start, int end, int maxSize) {
        if (this.plcStatus == null) {
            this.plcStatus = new int[maxSize];
        }

        for (int i = start; i < end; i++) {
            try {
                this.plcStatus[i] = plcStatus[i - start];
            } catch (ArrayIndexOutOfBoundsException e) {
                e.printStackTrace();
            }
        }
    }

    public long getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(long updateTime) {
        this.updateTime = updateTime;
    }

    public boolean isTimeOut() {
        return System.currentTimeMillis() - getUpdateTime() > TIME_OUT;
    }

}
